package dbmanager;

import java.sql.*;
import java.util.Hashtable;

/**
 * @author
 * This class Checks existence of string in Master_table and propety_detils table
 *   
 **/
public class ChekInMaster 
{
	DBManager db;
	String sqlTable = "master_table";	
	ResultSet rs;
	/**
	 * Parameterise Constructor
	 * @param db Gets DBManager object reference
	 * @exception Exception
	 * **/
	public ChekInMaster(DBManager db) 
	{
		this.db = db;
	}
	/**
	 * Parameterise Constructor
	 * @param db Gets DBManager object reference
	 * @exception Exception
	 * **/
	public boolean isInMaster(String word)
	{
		boolean isInMaster = false;
		try
		{
			String _query = "SELECT distinct Name FROM "+sqlTable+" WHERE lower(Name)=lower('"+word+"')";
			ResultSet rs2 = db.getSelect(_query);
			if(rs2.next())
			{
				System.out.println("utility::ChekInMaster::isInMaster()::The word in master is "+rs2.getString(1));
				isInMaster = true;
			}
			else
			{
				System.out.println("utility::ChekInMaster::isInMaster()::The word is not in master"+word);
				isInMaster = false;
			}
		}
		catch(Exception e)
		{
			System.out.println("utility::ChekInMaster::isInMaster():: Error in isInMaster(String word)");
			e.printStackTrace();
			return(false);
		}
		return(isInMaster);
	}
	/**
	 * This method is used to check given string in master table
	 * @return  true Existence of Specified string
	 * @param word  Gets the string
	 * @param hasht Gets the hash map values
	 * 	 * **/
	public boolean isInProperty_details(Hashtable<Object, Object> hasht,String tableName)
	{
		boolean isInProperty_details = false;
		try
		{
			ResultSet rs  = db.getselect(hasht, tableName);
			
			if(rs.next())
			{
				System.out.println("utility::ChekInMaster::isInProperty_details()::The word is present");
				isInProperty_details = true;
			}
			else
			{
				System.out.println("utility::ChekInMaster::isInProperty_details()::The word is not present");
				isInProperty_details = false;
			}
		}
		catch(Exception e)
		{
			System.out.println("utility::isInProperty_details::isInProperty_details():: Error in isInProperty_details(String word)");
			e.printStackTrace();
			return(false);
		}
		return(isInProperty_details);
	}
}